<div class="container-fluid">
    年:<input type="text" id="year">
    月:<input type="text" id="month"/>
    <button class="btn btn-primary" type="button" onclick="somainReport()">查询</button>
</div>
<table class="table" id="somainDiv">
    <thead>
    <tr>
        <th>销售单总数</th>
        <th>已了结数</th>
        <th>销售单总金额</th>
        <th>已收款金额</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody id="tableBody">
    <tr>
        <td id="somainNum"></td>
        <td id="endNum"></td>
        <td id="somainPrice"></td>
        <td id="endSomainPrice"></td>
        <td hidden id="button"><input type="button" value="查看明细" onclick="toSoItemReport()"></td>
    </tr>
    </tbody>
</table>
<script>
    function somainReport() {
        var year=$("#year").val()
        var month=$("#month").val()
        if(Number(month)<9){
            var date=year+"-0"+month+"~"+year+"-0"+(Number(month)+1)
        }
        if(Number(month)==9){
            var date=year+"-0"+month+"~"+year+"-"+(Number(month)+1)
        }
        if(Number(month)>9){
            var date=year+"-"+month+"~"+year+"-"+(Number(month)+1)
        }
        window.sessionStorage.setItem("somaindate",date)
        Ajax.post(
            "/selectSoMainNum",
            {date:date},
            function (result) {
                document.getElementById("somainNum").innerText=result.data.length
                var sum=0
                for(var i=0;i<result.data.length;i++){
                    sum=sum+result.data[i].soTotal
                }
                document.getElementById("somainPrice").innerText=sum
            }
        )
        Ajax.post(
            "/selectSoMainEndNum",
            {date:date},
            function (result) {
                document.getElementById("endNum").innerText=result.data
            }
        )
        Ajax.post(
            "/selectEndSomainPrice",
            {date:date},
            function (result) {
                var sum=0
                for(var i=0;i<result.data.length;i++){
                    if(result.data[i].status==3||result.data[i].status==4){
                        sum=sum+result.data[i].soTotal
                    }
                    if(result.data[i].status==5){
                        sum=sum+result.data[i].prePayFee
                    }
                    if(result.data[i].status==2&&result.data[i].payType=="预付款发货"){
                        sum=sum+result.data[i].prePayFee
                    }
                }
                console.log(sum)
                document.getElementById("endSomainPrice").innerText=sum
            }
        )
        $("#button").attr("hidden",false)
    }
    function toSoItemReport() {
        show("/report/soItemReport.html")
    }
</script>